#include <iostream>
#include <unistd.h>
#include "Options/Options.hpp"
#include "Kitchen.hpp"

namespace pizzeria {

Kitchen::Kitchen() {
  mWalkieTalkie = NULL;
}

Kitchen::Kitchen(communication::WalkieTalkie *walkieTalkie) {
  mWalkieTalkie = walkieTalkie;
  mCooks.resize(Options::GetInstance().GetCooksPerKitchen());
  Loop();
}

Kitchen::~Kitchen() {

}

void Kitchen::Loop() {
  while (true) {
    communication::Message msg = mWalkieTalkie->Receive();
    if (msg.GetType() == communication::Message::NEW_ORDER) {
      const Pizza *pizza = dynamic_cast<const Pizza *>(msg.GetData());
      mCooks[0].CookPizza(*pizza);
    }
  }
}

std::string Kitchen::Serialize() const {
  return "";
}

void Kitchen::Deserialize(const std::string &data) {
  (void) data;
}

size_t Kitchen::GetSerializedSize() const {
  return 0;
}

void *Kitchen::CreateKitchen(void *walkieTalkie) {
  Kitchen kitchen(static_cast<communication::WalkieTalkie *>(walkieTalkie));
  return NULL;
}

} /* !namespace pizzeria */
